package com.hoo.service.equipment;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.mapper.BeanMapper;

import com.hoo.entity.equipment.Advertise;
import com.hoo.entity.equipment.AdvertiseType;
import com.hoo.form.equipment.AdvertiseForm;
import com.hoo.mapper.equipment.AdvertiseMapper;
import com.hoo.util.PaginationSupport;

@Service
public class AdvertiseService {
	@Autowired
	AdvertiseMapper advertiseMapper;

	public PaginationSupport<Advertise> search() {
		return new PaginationSupport<Advertise>(this.advertiseMapper.getAdvertiseList(new AdvertiseForm()), this.advertiseMapper.getAdvertiseCount());
	}
	
	@Transactional(propagation=Propagation.REQUIRED,readOnly=false)
	public int deleteAdvertiseById(int id) {
		return this.advertiseMapper.deleteAdvertiseById(id);
	}

	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	public Advertise getAdvertiseById(Integer id) {
		return this.advertiseMapper.getAdvertiseById(id);
	}

	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	public List<AdvertiseType> getAllAdvertiseType() {
		return this.advertiseMapper.getAllAdvertiseType();
	}

	@Transactional(propagation=Propagation.REQUIRED,readOnly=false)
	public int updateAdvertise(AdvertiseForm form) {
		form.setUpdateTime(new Date());
		return this.advertiseMapper.updateAdvertise(BeanMapper.map(form, Advertise.class));
	}

	@Transactional(propagation=Propagation.REQUIRED,readOnly=false)
	public int insertAdvertise(AdvertiseForm form) {
		form.setAddTime(new Date());
		return this.advertiseMapper.insertAdvertise(BeanMapper.map(form, Advertise.class));
	}
	
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	public List<Advertise> getAllAdvertise(){
		return this.advertiseMapper.getAllAdvertise();
	}
	
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	public List<Advertise> getAdvertiseListByMachineIp(String ip){
		return this.advertiseMapper.getAdvertiseListByMachineIp(ip);
	}
}
